package com.ciccwm.core.validation.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;
import com.ciccwm.core.validation.annotation.Phone;

/**
 * 手机号码验证器.
 *
 * @author ciccwm
 */
public class PhoneValidator implements ConstraintValidator<Phone, String> {
    private static final String PHONE_PATTERN = "^1[3-9]\\d{9}$";
    private static final Pattern PATTERN = Pattern.compile(PHONE_PATTERN);

    @Override
    public void initialize(Phone constraintAnnotation) {
        // 初始化验证器
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return true;
        }
        return PATTERN.matcher(value).matches();
    }
} 
